{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>turnover</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>23.53</td>\n",
       "      <td>25.88</td>\n",
       "      <td>24.16</td>\n",
       "      <td>23.53</td>\n",
       "      <td>95578.03</td>\n",
       "      <td>0.63</td>\n",
       "      <td>2.68</td>\n",
       "      <td>2.39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>22.80</td>\n",
       "      <td>23.78</td>\n",
       "      <td>23.53</td>\n",
       "      <td>22.80</td>\n",
       "      <td>60985.11</td>\n",
       "      <td>0.69</td>\n",
       "      <td>3.02</td>\n",
       "      <td>1.53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>22.88</td>\n",
       "      <td>23.37</td>\n",
       "      <td>22.82</td>\n",
       "      <td>22.71</td>\n",
       "      <td>52914.01</td>\n",
       "      <td>0.54</td>\n",
       "      <td>2.42</td>\n",
       "      <td>1.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>22.25</td>\n",
       "      <td>22.76</td>\n",
       "      <td>22.28</td>\n",
       "      <td>22.02</td>\n",
       "      <td>36105.01</td>\n",
       "      <td>0.36</td>\n",
       "      <td>1.64</td>\n",
       "      <td>0.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>21.49</td>\n",
       "      <td>21.99</td>\n",
       "      <td>21.92</td>\n",
       "      <td>21.48</td>\n",
       "      <td>23331.04</td>\n",
       "      <td>0.44</td>\n",
       "      <td>2.05</td>\n",
       "      <td>0.58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.48</td>\n",
       "      <td>14.28</td>\n",
       "      <td>13.13</td>\n",
       "      <td>179831.72</td>\n",
       "      <td>1.12</td>\n",
       "      <td>8.51</td>\n",
       "      <td>6.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.45</td>\n",
       "      <td>13.16</td>\n",
       "      <td>12.87</td>\n",
       "      <td>93180.39</td>\n",
       "      <td>0.26</td>\n",
       "      <td>2.02</td>\n",
       "      <td>3.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>12.61</td>\n",
       "      <td>67075.44</td>\n",
       "      <td>0.20</td>\n",
       "      <td>1.57</td>\n",
       "      <td>2.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>13.06</td>\n",
       "      <td>12.70</td>\n",
       "      <td>12.52</td>\n",
       "      <td>139071.61</td>\n",
       "      <td>0.18</td>\n",
       "      <td>1.44</td>\n",
       "      <td>4.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.67</td>\n",
       "      <td>12.52</td>\n",
       "      <td>12.20</td>\n",
       "      <td>96291.73</td>\n",
       "      <td>0.32</td>\n",
       "      <td>2.62</td>\n",
       "      <td>3.30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>643 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low     volume  price_change  p_change  \\\n",
       "2018-02-27  23.53  25.88  24.16  23.53   95578.03          0.63      2.68   \n",
       "2018-02-26  22.80  23.78  23.53  22.80   60985.11          0.69      3.02   \n",
       "2018-02-23  22.88  23.37  22.82  22.71   52914.01          0.54      2.42   \n",
       "2018-02-22  22.25  22.76  22.28  22.02   36105.01          0.36      1.64   \n",
       "2018-02-14  21.49  21.99  21.92  21.48   23331.04          0.44      2.05   \n",
       "...           ...    ...    ...    ...        ...           ...       ...   \n",
       "2015-03-06  13.17  14.48  14.28  13.13  179831.72          1.12      8.51   \n",
       "2015-03-05  12.88  13.45  13.16  12.87   93180.39          0.26      2.02   \n",
       "2015-03-04  12.80  12.92  12.90  12.61   67075.44          0.20      1.57   \n",
       "2015-03-03  12.52  13.06  12.70  12.52  139071.61          0.18      1.44   \n",
       "2015-03-02  12.25  12.67  12.52  12.20   96291.73          0.32      2.62   \n",
       "\n",
       "            turnover  \n",
       "2018-02-27      2.39  \n",
       "2018-02-26      1.53  \n",
       "2018-02-23      1.32  \n",
       "2018-02-22      0.90  \n",
       "2018-02-14      0.58  \n",
       "...              ...  \n",
       "2015-03-06      6.16  \n",
       "2015-03-05      3.19  \n",
       "2015-03-04      2.30  \n",
       "2015-03-03      4.76  \n",
       "2015-03-02      3.30  \n",
       "\n",
       "[643 rows x 8 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取数据\n",
    "data = pd.read_csv('../../../data/stock_day.csv')\n",
    "data = data.drop([\"ma5\",\"ma10\",\"ma20\",\"v_ma5\",\"v_ma10\",\"v_ma20\"], axis=1)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([1, 0, 4, 3, 2, 1, 0, 4, 3, 2,\n",
       "            ...\n",
       "            4, 3, 2, 1, 0, 4, 3, 2, 1, 0],\n",
       "           dtype='int64', length=643)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取日期\n",
    "week = pd.to_datetime(data.index).weekday\n",
    "week"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>turnover</th>\n",
       "      <th>week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>23.53</td>\n",
       "      <td>25.88</td>\n",
       "      <td>24.16</td>\n",
       "      <td>23.53</td>\n",
       "      <td>95578.03</td>\n",
       "      <td>0.63</td>\n",
       "      <td>2.68</td>\n",
       "      <td>2.39</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>22.80</td>\n",
       "      <td>23.78</td>\n",
       "      <td>23.53</td>\n",
       "      <td>22.80</td>\n",
       "      <td>60985.11</td>\n",
       "      <td>0.69</td>\n",
       "      <td>3.02</td>\n",
       "      <td>1.53</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>22.88</td>\n",
       "      <td>23.37</td>\n",
       "      <td>22.82</td>\n",
       "      <td>22.71</td>\n",
       "      <td>52914.01</td>\n",
       "      <td>0.54</td>\n",
       "      <td>2.42</td>\n",
       "      <td>1.32</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>22.25</td>\n",
       "      <td>22.76</td>\n",
       "      <td>22.28</td>\n",
       "      <td>22.02</td>\n",
       "      <td>36105.01</td>\n",
       "      <td>0.36</td>\n",
       "      <td>1.64</td>\n",
       "      <td>0.90</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>21.49</td>\n",
       "      <td>21.99</td>\n",
       "      <td>21.92</td>\n",
       "      <td>21.48</td>\n",
       "      <td>23331.04</td>\n",
       "      <td>0.44</td>\n",
       "      <td>2.05</td>\n",
       "      <td>0.58</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-06</th>\n",
       "      <td>13.17</td>\n",
       "      <td>14.48</td>\n",
       "      <td>14.28</td>\n",
       "      <td>13.13</td>\n",
       "      <td>179831.72</td>\n",
       "      <td>1.12</td>\n",
       "      <td>8.51</td>\n",
       "      <td>6.16</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-05</th>\n",
       "      <td>12.88</td>\n",
       "      <td>13.45</td>\n",
       "      <td>13.16</td>\n",
       "      <td>12.87</td>\n",
       "      <td>93180.39</td>\n",
       "      <td>0.26</td>\n",
       "      <td>2.02</td>\n",
       "      <td>3.19</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-04</th>\n",
       "      <td>12.80</td>\n",
       "      <td>12.92</td>\n",
       "      <td>12.90</td>\n",
       "      <td>12.61</td>\n",
       "      <td>67075.44</td>\n",
       "      <td>0.20</td>\n",
       "      <td>1.57</td>\n",
       "      <td>2.30</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-03</th>\n",
       "      <td>12.52</td>\n",
       "      <td>13.06</td>\n",
       "      <td>12.70</td>\n",
       "      <td>12.52</td>\n",
       "      <td>139071.61</td>\n",
       "      <td>0.18</td>\n",
       "      <td>1.44</td>\n",
       "      <td>4.76</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2015-03-02</th>\n",
       "      <td>12.25</td>\n",
       "      <td>12.67</td>\n",
       "      <td>12.52</td>\n",
       "      <td>12.20</td>\n",
       "      <td>96291.73</td>\n",
       "      <td>0.32</td>\n",
       "      <td>2.62</td>\n",
       "      <td>3.30</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>643 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low     volume  price_change  p_change  \\\n",
       "2018-02-27  23.53  25.88  24.16  23.53   95578.03          0.63      2.68   \n",
       "2018-02-26  22.80  23.78  23.53  22.80   60985.11          0.69      3.02   \n",
       "2018-02-23  22.88  23.37  22.82  22.71   52914.01          0.54      2.42   \n",
       "2018-02-22  22.25  22.76  22.28  22.02   36105.01          0.36      1.64   \n",
       "2018-02-14  21.49  21.99  21.92  21.48   23331.04          0.44      2.05   \n",
       "...           ...    ...    ...    ...        ...           ...       ...   \n",
       "2015-03-06  13.17  14.48  14.28  13.13  179831.72          1.12      8.51   \n",
       "2015-03-05  12.88  13.45  13.16  12.87   93180.39          0.26      2.02   \n",
       "2015-03-04  12.80  12.92  12.90  12.61   67075.44          0.20      1.57   \n",
       "2015-03-03  12.52  13.06  12.70  12.52  139071.61          0.18      1.44   \n",
       "2015-03-02  12.25  12.67  12.52  12.20   96291.73          0.32      2.62   \n",
       "\n",
       "            turnover  week  \n",
       "2018-02-27      2.39     1  \n",
       "2018-02-26      1.53     0  \n",
       "2018-02-23      1.32     4  \n",
       "2018-02-22      0.90     3  \n",
       "2018-02-14      0.58     2  \n",
       "...              ...   ...  \n",
       "2015-03-06      6.16     4  \n",
       "2015-03-05      3.19     3  \n",
       "2015-03-04      2.30     2  \n",
       "2015-03-03      4.76     1  \n",
       "2015-03-02      3.30     0  \n",
       "\n",
       "[643 rows x 9 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 向原始数据中添加日期列\n",
    "data['week'] = week\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 统计股票涨跌情况，用1表示涨，用0表\n",
    "p_n = np.where(data['p_change']>0, 1, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>close</th>\n",
       "      <th>low</th>\n",
       "      <th>volume</th>\n",
       "      <th>price_change</th>\n",
       "      <th>p_change</th>\n",
       "      <th>turnover</th>\n",
       "      <th>week</th>\n",
       "      <th>p_n</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-02-27</th>\n",
       "      <td>23.53</td>\n",
       "      <td>25.88</td>\n",
       "      <td>24.16</td>\n",
       "      <td>23.53</td>\n",
       "      <td>95578.03</td>\n",
       "      <td>0.63</td>\n",
       "      <td>2.68</td>\n",
       "      <td>2.39</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-26</th>\n",
       "      <td>22.80</td>\n",
       "      <td>23.78</td>\n",
       "      <td>23.53</td>\n",
       "      <td>22.80</td>\n",
       "      <td>60985.11</td>\n",
       "      <td>0.69</td>\n",
       "      <td>3.02</td>\n",
       "      <td>1.53</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-23</th>\n",
       "      <td>22.88</td>\n",
       "      <td>23.37</td>\n",
       "      <td>22.82</td>\n",
       "      <td>22.71</td>\n",
       "      <td>52914.01</td>\n",
       "      <td>0.54</td>\n",
       "      <td>2.42</td>\n",
       "      <td>1.32</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-22</th>\n",
       "      <td>22.25</td>\n",
       "      <td>22.76</td>\n",
       "      <td>22.28</td>\n",
       "      <td>22.02</td>\n",
       "      <td>36105.01</td>\n",
       "      <td>0.36</td>\n",
       "      <td>1.64</td>\n",
       "      <td>0.90</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-14</th>\n",
       "      <td>21.49</td>\n",
       "      <td>21.99</td>\n",
       "      <td>21.92</td>\n",
       "      <td>21.48</td>\n",
       "      <td>23331.04</td>\n",
       "      <td>0.44</td>\n",
       "      <td>2.05</td>\n",
       "      <td>0.58</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-13</th>\n",
       "      <td>21.40</td>\n",
       "      <td>21.90</td>\n",
       "      <td>21.48</td>\n",
       "      <td>21.31</td>\n",
       "      <td>30802.45</td>\n",
       "      <td>0.28</td>\n",
       "      <td>1.32</td>\n",
       "      <td>0.77</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-12</th>\n",
       "      <td>20.70</td>\n",
       "      <td>21.40</td>\n",
       "      <td>21.19</td>\n",
       "      <td>20.63</td>\n",
       "      <td>32445.39</td>\n",
       "      <td>0.82</td>\n",
       "      <td>4.03</td>\n",
       "      <td>0.81</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-09</th>\n",
       "      <td>21.20</td>\n",
       "      <td>21.46</td>\n",
       "      <td>20.36</td>\n",
       "      <td>20.19</td>\n",
       "      <td>54304.01</td>\n",
       "      <td>-1.50</td>\n",
       "      <td>-6.86</td>\n",
       "      <td>1.36</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-08</th>\n",
       "      <td>21.79</td>\n",
       "      <td>22.09</td>\n",
       "      <td>21.88</td>\n",
       "      <td>21.75</td>\n",
       "      <td>27068.16</td>\n",
       "      <td>0.09</td>\n",
       "      <td>0.41</td>\n",
       "      <td>0.68</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-02-07</th>\n",
       "      <td>22.69</td>\n",
       "      <td>23.11</td>\n",
       "      <td>21.80</td>\n",
       "      <td>21.29</td>\n",
       "      <td>53853.25</td>\n",
       "      <td>-0.50</td>\n",
       "      <td>-2.24</td>\n",
       "      <td>1.35</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high  close    low    volume  price_change  p_change  \\\n",
       "2018-02-27  23.53  25.88  24.16  23.53  95578.03          0.63      2.68   \n",
       "2018-02-26  22.80  23.78  23.53  22.80  60985.11          0.69      3.02   \n",
       "2018-02-23  22.88  23.37  22.82  22.71  52914.01          0.54      2.42   \n",
       "2018-02-22  22.25  22.76  22.28  22.02  36105.01          0.36      1.64   \n",
       "2018-02-14  21.49  21.99  21.92  21.48  23331.04          0.44      2.05   \n",
       "2018-02-13  21.40  21.90  21.48  21.31  30802.45          0.28      1.32   \n",
       "2018-02-12  20.70  21.40  21.19  20.63  32445.39          0.82      4.03   \n",
       "2018-02-09  21.20  21.46  20.36  20.19  54304.01         -1.50     -6.86   \n",
       "2018-02-08  21.79  22.09  21.88  21.75  27068.16          0.09      0.41   \n",
       "2018-02-07  22.69  23.11  21.80  21.29  53853.25         -0.50     -2.24   \n",
       "\n",
       "            turnover  week  p_n  \n",
       "2018-02-27      2.39     1    1  \n",
       "2018-02-26      1.53     0    1  \n",
       "2018-02-23      1.32     4    1  \n",
       "2018-02-22      0.90     3    1  \n",
       "2018-02-14      0.58     2    1  \n",
       "2018-02-13      0.77     1    1  \n",
       "2018-02-12      0.81     0    1  \n",
       "2018-02-09      1.36     4    0  \n",
       "2018-02-08      0.68     3    1  \n",
       "2018-02-07      1.35     2    0  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 向原始数据中添加股票涨跌列\n",
    "data['p_n'] = p_n\n",
    "data.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>col_0</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_0</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>63</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>55</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>61</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>63</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>59</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "col_0   0   1\n",
       "row_0        \n",
       "0      63  62\n",
       "1      55  76\n",
       "2      61  71\n",
       "3      63  65\n",
       "4      59  68"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用交叉表查看周n和股票涨跌的关系\n",
    "count = pd.crosstab(week, p_n)\n",
    "count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 计算每周n的涨跌情况\n",
    "sum = count.sum(axis=1)\n",
    "count = count.div(sum, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1768d724fc8>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAABIAAAAHaCAYAAAB4hTJsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy86wFpkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAZZUlEQVR4nO3db6ye9X3f8c+32CE2rgMM4xWS1HJhEmETTeItOHMzJxsNiKRIKBDSiCn9M2vZn+7hwmBbVqF1Y1WeTCKaW6pOWhOJbtRSlUbQdXFgkpPomISklE2dJqPGlbE7XJ96gY3R3x74JIYjH87tc+7jm/P16/WE69z3776vrx9cOkdvrj81xggAAAAAff3QrAcAAAAAYG0JQAAAAADNCUAAAAAAzQlAAAAAAM0JQAAAAADNCUAAAAAAzW2YxU6vuuqqsWPHjlnsGgAAAKClw4cP/8kYY9u53ptJANqxY0fm5uZmsWsAAACAlqrq+aXecwkYAAAAQHMCEAAAAEBzAhAAAABAcwIQAAAAQHMCEAAAAEBzAhAAAABAczN5DDwAAADAas3Pz+f48eN55ZVXZj3Kmtu4cWOuvvrqbN26dUWfF4AAAACAdWd+fj4vvPBCrr322mzatClVNeuR1swYIy+99FKOHj2aJCuKQC4BAwAAANad48eP59prr83mzZtbx58kqaps3rw51157bY4fP76i7xCAAAAAgHXnlVdeyaZNm2Y9xgW1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OAAICLTlUdrKp/U1WPL/x8aVV9saq+WlW/UVVvqaq5qrq6ql6oqh+pqt9Z4uv2Jnl0YfuJJHsuwD8BAOC8CEAAwMXo5iSHxhgfXvj57yT5/THG30jyh0l+Nsn/TPLhJN9I8pNJnl7iuy5LcnRh+8Uk29dqaACAlRKAAICL0e+PMR57zc/vSvL1he2vJbkhZ4LP3Um+lOSuJIeX+K7TSTYtbG+Jv68AgDchf6AAABej04t+fjZnzgrKwn+fTfLNJB9K8p9z5kygpc4AOpyzl33dlOTINAcFAJiGDbMeAADgTeBXk/x6VT2Z5I+S/Mskb0vyfM5cCnZ8jPH8Ep89kOSpqromyW05G5IAAN40aowx6xkAANa1qroiyS1JnhxjHJv1PAAAiwlAAAATqqqDi146Nca4YxazAACcDwEIAAAAoDk3gQYAAABoTgACAAAAaE4AAgAAAGhOAAIAAABoTgACAAAAaO7/A0GTmQ7OLEF0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 1440x576 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "count.plot(kind='bar', figsize=(20, 8), stacked=True)  # stacked=True表示柱状图进行堆积\n",
    "plt.legend(fontsize=15)\n",
    "# plt.xticks(fontsize=20, color='w')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>p_n</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>week</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.496000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.580153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.537879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.507812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.535433</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           p_n\n",
       "week          \n",
       "0     0.496000\n",
       "1     0.580153\n",
       "2     0.537879\n",
       "3     0.507812\n",
       "4     0.535433"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 透视表\n",
    "data.pivot_table(['p_n'], index='week')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
